#if !defined(HEIGHTMAP_H)
#define HEIGHTMAP_H

#include <vector>
#include "mathlib.h"

class HeightMap
{
public:
    HeightMap();
    ~HeightMap();

	void SetHeightAtIndex(int index, float h) {
		heightList[index] = h;
	}

	float heightAtIndex(int index) const
    { return heightList[index]; };

	float getWaterLevel() const
    { return water_height; }

    float getHeightScale() const
    { return heightScale; }

    int getSize() const
    { return sizeOfMap; }

    int getGridSpacing() const
    { return gridSpace; }

    const float *getHeights() const
    { return &heightList[0]; }

    bool create(int size, int gridSpacing, float scale);
    void destroy();

    void createNewFractal(float roughness);

    float heightAt(float x, float z) const;

    float heightAtPixel(int x, int z) const
    { return heightList[z * sizeOfMap + x]; };

    void normalAt(float x, float z, Vector3 &n) const;
    void normalAtPixel(int x, int z, Vector3 &n) const;

private:
    void blur(float amount);
    unsigned int heightIndexAt(int x, int z) const;
    void smooth();

	float water_height;
    int sizeOfMap;
    int gridSpace;
    float heightScale;
    std::vector<float> heightList;
};

#endif
